#include "viewer.h"

#include <QPixmap>
#include <QDebug>

#define USE_QT_RES

#ifdef USE_QT_RES
    #define PIC1_PATH ":/1.bmp"
    #define PIC2_PATH ":/2.bmp"
#else
    #define PIC1_PATH "/home/yyx/pic/1.bmp"
    #define PIC2_PATH "/home/yyx/pic/2.bmp"
#endif

Viewer::Viewer(QWidget *parent) :
    QWidget(parent)
{
    button = new QPushButton("next");
    label = new QLabel();

    QPixmap pixmap(PIC1_PATH);
    label->setPixmap(pixmap);

    layout = new QVBoxLayout();
    layout->addWidget(label);
    layout->addWidget(button);

    this->setFixedSize(800, 480);
    setLayout(layout);

    connect(button, SIGNAL(clicked(bool)), this, SLOT(on_button_click()));
}

Viewer::~Viewer()
{

}

void Viewer::on_button_click()
{
   static int cnt = 1;
   QPixmap pixmap;
   qDebug() << "button click";
   if (cnt++%2) {
        pixmap.load(PIC2_PATH);
   } else {
        pixmap.load(PIC1_PATH);
   }

   label->setPixmap(pixmap);
   label->update();
}
